package com.cskaoyan.controller.admin_promotion_controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.promotionVO.topicVO.TopicListVO;
import com.cskaoyan.service.promotionService.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AdminTopicController {

    @Autowired
    TopicService topicService;

    @RequestMapping("/admin/topic/list")
    public BaseRespVo topicList(Integer page, Integer limit, String sort, String order, String title, String subtitle) {
        TopicListVO topicListVO = topicService.topicList(page, limit, sort, order, title, subtitle);

        return BaseRespVo.ok(topicListVO);
    }

    @RequestMapping("/admin/topic/create")
    public BaseRespVo topicAdd(@RequestBody Topic topic) {
        Topic topicVO=topicService.topicAdd(topic);

        return BaseRespVo.ok(topicVO);
    }

    @RequestMapping("/admin/topic/update")
    public BaseRespVo topicUpdate(@RequestBody Topic topic) {
        Topic topicVO=topicService.topicUpdate(topic);

        return BaseRespVo.ok(topicVO);
    }

    @RequestMapping("/admin/topic/delete")
    public BaseRespVo topicDel(@RequestBody Topic topic) {
        topic.setDeleted(true);
        int code=topicService.topicDel(topic);

        if (code == 1) {
            return BaseRespVo.ok();
        } else {
            return BaseRespVo.fail();
        }

    }

}
